package com.foreverwin.jzymes.production.picking.service.impl;

import com.foreverwin.jzymes.framework.util.I18nUtil;
import com.foreverwin.jzymes.production.picking.domain.PickDocumentInfo;
import com.foreverwin.jzymes.production.picking.domain.PickingBillLog;
import com.foreverwin.jzymes.production.picking.enums.PickingstatusEnum;
import com.foreverwin.jzymes.production.picking.mapper.PickingMapper;
import com.foreverwin.jzymes.production.picking.service.IPickingBillLogService;
import com.foreverwin.jzymes.production.picking.service.IPickFeedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;

import java.util.Date;

import javax.jws.WebService;

@WebService( targetNamespace = "http;//webservice.jzymes.foreverwin.com/", endpointInterface = "com.foreverwin.jzymes.production.picking.service.IPickFeedService")
public class PickFeedServiceImpl implements IPickFeedService {
     @Autowired
    PickingMapper pickingMapper;
     @Autowired
     IPickingBillLogService pickingBillLogService;

     /**OA传ERP审核结果、调webService*/
    @Override
    public String feedPickDocumnet(PickDocumentInfo pickDocumentInfo) {
       String request =  pickDocumentInfo.getRequestId();
        String status = pickDocumentInfo.getStatus();
        String erpDoc = pickDocumentInfo.getErpDoc();
        String erpMessage = pickDocumentInfo.getErpMessage();

        PickingBillLog pickingBillLog = pickingMapper.selectPickingByRequestId( request );
        Assert.notNull( pickingBillLog , I18nUtil.getI18nText( "production.picking.picking" ));

        /**update status,end_time*/
        if ( status.equals( "0" ) ){

            pickingBillLog.setStatus( PickingstatusEnum.FAIL.name() );
            pickingBillLog.setEndDateTime( new Date() );
            pickingBillLog.setErpMessage( erpMessage );
            pickingBillLogService.updatePickingBillLog( pickingBillLog );

        }else{

            pickingBillLog.setStatus( PickingstatusEnum.PASS.name() );
            pickingBillLog.setEndDateTime( new Date() );
            pickingBillLog.setErpDoc( erpDoc );
            pickingBillLog.setErpMessage( erpMessage );
            pickingBillLogService.updatePickingBillLog( pickingBillLog );

        }

        return "操作成功";
    }
}
